import { View, Text,Image } from '@tarojs/components'
import {useState,useEffect} from 'react'
import { AtIcon } from 'taro-ui'
import Taro from '@tarojs/taro'
import './footprint.less'
import HTTP  from '../../service/api'
import store  from '../../store/index.js'
// import img from '../../img/1.png'

const Footprint=()=>{
    const [click,setClick]=useState(false)
    const clear=()=>{
        setClick(!click)
    }
    const [footInfo,setFootinfo]=useState([])
    setTimeout(()=>{
        Taro.request({
            url:HTTP.api2+'/userFootprint/findUserFootprints',
            method:'post',
             header:{
                 'content-type':'application/x-www-form-urlencoded'
             },
             data:{
                 uid:'1'
             },
             success:function(res) {
                 setFootinfo(res.data.footprints)
             }
         })
    },1000)
    const  date=new Date();
    
    const newdate=date.getFullYear()+'-'+ date.getMonth()+'-'+date.getDate();
    console.log(newdate);
    const xiangqing=(item)=>{
        console.log(item.gid,item.bid);
        // Taro.request({
        //     url:HTTP.api2+'/goodsDetails/find',
        //     method:'post',
        //     header:{
        //         "content-type":'application/x-www-form-urlencoded'
        //     },
        //     data:{
        //         uid:JSON.parse(JSON.stringify(store.userInformation.id)),
        //         gid:item.gid,
        //         bid:item.bid
        //     }
        // }).then(res=>{
        //     console.log(res.data);
        //     store.setXiangqingData(res.data)
        // })
        // console.log(store.footdata);
        //把当前行数据保存在mobx中，不再请求跳转，detail页面从store页面取数据
        store.setDataId(item.gid);
        store.setSid(item.bid);
        setTimeout(()=>{
            Taro.navigateTo({
                url:'/pages/details/details'
            })
        },3000)

    }
    return (
        <View >
            <View className='top'>
                <View className='zuji'>我的足迹</View>
                <View className='zjRight'>
                    <AtIcon value='trash' size='30' ></AtIcon>
                    <Text onClick={clear} style={click?{cursor:'not-allowed'}:{cursor:'none'}}>清除所有</Text>
                </View>
            </View>
            <View style={click?{display:'none'}:{display:'block'}}>
                <View className='timePic'>
                    <Text style={{fontWeight:'bold'}}>{newdate?'今天':'昨天'}</Text>
                       <View className='PicList'>
                       {footInfo.map((item,index)=>
                        <Image src={item.img} onClick={()=>(xiangqing(item))}>{index}</Image>
                    )}
                    </View>
                </View>
            </View>
            <View style={click?{opacity:'block',textAlign:'center'}:{display:'none',cursor:'no-drop'}}>
                <Image style={{width:'200px',height:'200px'}} src="https://cloud.axureshop.com/gsc/NQ0NLC/48/6b/eb/486bebf923f04b4c91e131e47e565f00/images/%E9%AB%98%E4%BF%9D%E7%9C%9F%E4%BA%A4%E4%BA%92%EF%BC%88h5_%E5%B0%8F%E7%A8%8B%E5%BA%8F%EF%BC%89/%E6%B8%85%E6%A5%9A%E6%89%80%E6%9C%89_u192.png?token=cdc0cdc44f9f19c8d3574302e892ec8a74e6d1eaa1d2f29c3188a3603fe66592"></Image>
                <br/>
                <View style={{textAlign:'center'}}>暂无足迹</View>
            </View>
        </View>
    )

}
export default Footprint;